package java;

import java.util.concurrent.*;

public class ThreadTest {
    public static void main(String[] args) {
        Person person = new Person();
        Thread a = new Thread(person);
        a.start();
        Thread c = new Thread(person);
        c.start();
        Thread b = new Thread(person);
        b.start();
        b.interrupt();

        Machine machine = new Machine();
        FutureTask<Integer> futureTask = new FutureTask<>(machine);
        new Thread(futureTask).start();

        ExecutorService pool = Executors.newFixedThreadPool(5);
        pool.submit(person);
        pool.shutdown();

        Thread thread = new MyThread();
        thread.start();
    }

    static class Person implements Runnable {

        @Override
        public void run() {
            try {
                System.out.println(Thread.currentThread().getName() + " sleep ...");
                Thread.sleep(5000);
                System.out.println(Thread.currentThread().getName() + " sleep over...");
            } catch (InterruptedException e) {
                System.out.println(Thread.currentThread().getName() + "被打断");
            }
        }
    }

    static class Machine implements Callable<Integer> {

        @Override
        public Integer call() throws Exception {
            Thread.sleep(5);
            System.out.println(Thread.currentThread().getName() + "run");
            return 1;
        }
    }

    static class MyThread extends Thread {
        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName() + "run");
        }
    }
}
